Repository navigation
fix(types): avoid excessive instantiation in typed $fetch responses - #36
Merged
Merged
Conversation
|
@brunobelloni is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
The fixture has too few routes to trigger the excessive instantiation, so the generic `$fetch` test passed before the fix too. Add an isolated type check with 400 typed routes that fails with TS2589 on the previous types.
commit: |
pi0
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
None. This is v2-only: Nitro v3 no longer ships the typed internal
$fetchtypes.❓ Type of change
📚 Description
With many typed routes in
InternalApi, calling$fetchfrom a generic function fails withTS2589: Type instantiation is excessively deep and possibly infinite:With a generic
T, theDefault extends ...check inTypedInternalResponseis deferred. TypeScript then computes the constraint of the distributiveRoute extends string ? ...branch, and that means instantiating it for everyInternalApikey.AvailableRouterMethodhas the same issue.This PR makes both public aliases non-distributive (
[R] extends [string]) and moves the per-route logic into internal helpers that still distribute over each member of a union of routes. For concrete routes the resulting types are the same: the existing fixture type tests pass unchanged. I added a type test for the two generic patterns above.On a standalone repro with 400 typed routes (TypeScript 6.0.3,
tsc --extendedDiagnostics):We hit this in a Nuxt 4 app and have carried the same change as a
pnpm patchsince October.📝 Checklist
🤖 Generated with Claude Code